
package com.lianxian.xindong.old.app;

import android.app.Application;
import android.content.Context;

import androidx.annotation.NonNull;

import com.hxb.library.base.delegate.AppLifecycles;
import com.hxb.library.integration.cache.IntelligentCache;
import com.hxb.library.utils.HxbUtils;
import com.lianxian.xindong.old.BuildConfig;
import com.lianxian.xindong.old.mvp.model.api.Api;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

import me.jessyan.retrofiturlmanager.RetrofitUrlManager;

/**
 * @作者： HeXingBo
 * @时间： 2022/11/10 10:49
 * @描述： 展示 {@link AppLifecycles} 的用法
 */
public class AppLifecyclesImpl implements AppLifecycles {

    @Override
    public void attachBaseContext(@NonNull Context base) {

    }

    @Override
    public void onCreate(@NonNull Application application) {
//        if (LeakCanary.isInAnalyzerProcess(application)) {
//            // This process is dedicated to LeakCanary for heap analysis.
//            // You should not init your app in this process.
//            return;
//        }
        //当所有模块集成到宿主 App 时, 在 App 中已经执行了以下代码
        if (BuildConfig.IS_BUILD_MODULE) {
            //使用 RetrofitUrlManager 切换 BaseUrl
            RetrofitUrlManager.getInstance().putDomain(Api.WORK_DOMAIN_NAME, Api.WORK_DOMAIN);
            //leakCanary内存泄露检查
            HxbUtils.obtainAppComponentFromContext(application).extras()
                    .put(IntelligentCache.getKeyOfKeep(RefWatcher.class.getName())
                            , BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);
        }
    }

    @Override
    public void onTerminate(@NonNull Application application) {

    }
}
